<?php
    // +----------------------------------------------------------------------
    // | 帮助
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------
    namespace app\controller\cms;

    use app\event\cms\Document as DocumentEvent;
    use app\model\cms\Category as CategoryModel;
	use app\event\store\Good as GoodEvent;
	use app\event\store\Store as StoreEvent;

	class Good extends Common
    {

        // 初始化
        protected function initialize()
        {
            parent::initialize();
            $this->assign('open_doc_id',0);
        }

        public function lists()
        {
			$this->assign('c_menu', 'product');
			$this->assign('lists', \app\model\store\Good::where('status',1)->limit(30)->select());
            return $this->fetch();
        }
        public function detail()
        {
			$good = new GoodEvent();
			$result = $good->detail($this->request->param());
			if (0 == $result['code']) {

				$this->assign('c_menu', 'product');
				$sku = $result['data']['sku'];
				$good = $result['data']['good'];
				$this->store = $good->store()->find();
				$visit = StoreEvent::visitCheck($this->store);
				if (0 !== $visit['code']) {
					$this->error($visit['message']);
				}
				$this->assign('store', $this->store);
				$this->assign('good', $good);
				$this->assign('sku_arr', $good['sku_arr']);
				$this->assign('data', $sku);
				$event = new GoodEvent();
				$lists = $event->recommends($this->request->param(), $this->user);
				$this->assign('recommends', $lists['data']);
				$lists = $event->recommends($this->request->param(), $this->user);
				$this->assign('likes', $lists['data']);
				// 评价
				$lists = $good->evaluates()->where('status', 1)->order('id DESC')->paginate();
				// 获取分页显示
				$page = $lists->render();
				$tags = $good->tags()->where('status',1)->select();
				$this->assign('tags', $tags);
				$this->assign('evaluates', $lists);
				$this->assign('page', $page);
				return $this->fetch();
//				return $this->fetch($this->store['home_template']);
			} else {
				$this->error('商品不存在或者已经下架');
			}

		}

        public function search()
        {
            $good_category = CategoryModel::where('status', 1)->where('is_recommend', 1)->where('pattern_id', 5)->order('sort ASC')->select();
            $this->assign('good_category', $good_category);
            return $this->fetch();
        }
    }
